package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.StringUtils;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.project.system.domain.UserRealAuth;
import com.happy.cat.project.system.service.IUserRealAuthService;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 用户实名认证Controller
 *
 * @author verne
 * @date 2020-08-07
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/userRealAuth" )
@Api("用户实名认证 API")
public class UserRealAuthController extends BaseController {

    private final IUserRealAuthService iUserRealAuthService;

    /**
     * 查询用户实名认证列表
     */
    @ApiOperation(value = "查询用户实名认证列表",notes = "查询用户实名认证列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:userRealAuth:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserRealAuth userRealAuth)
    {
        startPage();
        LambdaQueryWrapper<UserRealAuth> lqw = new LambdaQueryWrapper<UserRealAuth>();
        if (userRealAuth.getAccountId() != null){
            lqw.eq(UserRealAuth::getAccountId ,userRealAuth.getAccountId());
        }
        if (StringUtils.isNotBlank(userRealAuth.getName())){
            lqw.like(UserRealAuth::getName ,userRealAuth.getName());
        }
        if (StringUtils.isNotBlank(userRealAuth.getCard())){
            lqw.eq(UserRealAuth::getCard ,userRealAuth.getCard());
        }
        if (StringUtils.isNotBlank(userRealAuth.getPhoto())){
            lqw.eq(UserRealAuth::getPhoto ,userRealAuth.getPhoto());
        }
        if (userRealAuth.getAuditTime() != null){
            lqw.eq(UserRealAuth::getAuditTime ,userRealAuth.getAuditTime());
        }
        if (userRealAuth.getStatus() != null){
            lqw.eq(UserRealAuth::getStatus ,userRealAuth.getStatus());
        }
        if (StringUtils.isNotBlank(userRealAuth.getManageBy())){
            lqw.eq(UserRealAuth::getManageBy ,userRealAuth.getManageBy());
        }
        List<UserRealAuth> list = iUserRealAuthService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出用户实名认证列表
     */
    @ApiOperation(value = "导出用户实名认证列表",notes = "导出用户实名认证列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userRealAuth:export')" )
    @Log(title = "用户实名认证" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(UserRealAuth userRealAuth) {
        LambdaQueryWrapper<UserRealAuth> lqw = new LambdaQueryWrapper<UserRealAuth>(userRealAuth);
        List<UserRealAuth> list = iUserRealAuthService.list(lqw);
        ExcelUtil<UserRealAuth> util = new ExcelUtil<UserRealAuth>(UserRealAuth. class);
        return util.exportExcel(list, "userRealAuth" );
    }

    /**
     * 获取用户实名认证详细信息
     */
    @ApiOperation(value = "获取用户实名认证详细信息",notes = "获取用户实名认证详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userRealAuth:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iUserRealAuthService.getById(id));
    }

    /**
     * 新增用户实名认证
     */
    @ApiOperation(value = "新增用户实名认证",notes = "新增用户实名认证",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userRealAuth:add')" )
    @Log(title = "用户实名认证" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserRealAuth userRealAuth) {
        return toAjax(iUserRealAuthService.save(userRealAuth) ? 1 : 0);
    }

    /**
     * 修改用户实名认证
     */
    @ApiOperation(value = "修改用户实名认证",notes = "修改用户实名认证",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userRealAuth:edit')" )
    @Log(title = "用户实名认证" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserRealAuth userRealAuth) {
        return toAjax(iUserRealAuthService.updateById(userRealAuth) ? 1 : 0);
    }

    /**
     * 删除用户实名认证
     */
    @ApiOperation(value = "删除用户实名认证",notes = "删除用户实名认证",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userRealAuth:remove')" )
    @Log(title = "用户实名认证" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iUserRealAuthService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
